﻿alter table claims alter column S_N smallint not null
go
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[CLAIMS]') AND name = N'PK_CLAIMS')
ALTER TABLE [CLAIMS] DROP CONSTRAINT [PK_CLAIMS]
go
ALTER TABLE [CLAIMS] ADD  CONSTRAINT [PK_CLAIMS] PRIMARY KEY CLUSTERED ([S_N] ASC)
go
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[PaymentClaim_R01]') AND parent_object_id = OBJECT_ID(N'[PaymentClaim]'))
ALTER TABLE [PaymentClaim] DROP CONSTRAINT [PaymentClaim_R01]
go
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[PaymentClaim_R02]') AND parent_object_id = OBJECT_ID(N'[PaymentClaim]'))
ALTER TABLE [PaymentClaim] DROP CONSTRAINT [PaymentClaim_R02]
go
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[PaymentClaim]') AND type in (N'U'))
DROP TABLE [PaymentClaim]
go
CREATE TABLE [PaymentClaim](
	[PaymentClaimId] [int] IDENTITY(1,1) NOT NULL,
	[S_N] [smallint] NOT NULL,
	[PaymentId] [int] NOT NULL,
 CONSTRAINT [PK_PaymentClaim] PRIMARY KEY([PaymentClaimId] ASC)
)
go
ALTER TABLE [PaymentClaim] ADD  CONSTRAINT [PaymentClaim_R01] FOREIGN KEY([S_N])
REFERENCES [CLAIMS] ([S_N])
go
ALTER TABLE [PaymentClaim]  ADD CONSTRAINT [PaymentClaim_R02] FOREIGN KEY([PaymentId])
REFERENCES [Payment] ([PaymentId])
go
